class Solution {//leetcode515——再每个树行中找最大值
public:
    vector<int> largestValues(TreeNode* root) {
        vector<int> ret;
        if(root==nullptr) return ret;
        queue<TreeNode*> q;
        q.push(root);
        while(q.size()){
            int max_val=INT_MIN;
            int level=q.size();
            for(int i=0;i<level;i++){
                TreeNode* t=q.front();
                max_val=max(max_val,t->val);
                if(t->right) q.push(t->right);
                if(t->left) q.push(t->left);
                q.pop();
            }
            ret.push_back(max_val);
        }
        return ret;
    }
};